package com.agile.leetcode.properties;

import java.io.*;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 * @Author ChenZhangKun
 * @Date 2020/12/28 15:21
 */
public class PropertiesDemo {
    public static void main(String[] args) throws IOException {
        PropertiesDemo propertiesDemo = new PropertiesDemo();
        propertiesDemo.fun_2();
        propertiesDemo.fun_3();
    }

    /**
     * 从类路径下获取
     *
     * @throws IOException
     */
    public void fun_1() throws IOException {
        Properties properties = new Properties();
        InputStream inputStream = PropertiesDemo.class.getClassLoader().getResourceAsStream("config/info.properties");
        properties.load(inputStream);
        System.out.println(properties.getProperty("name"));
    }

    /**
     * 从任意位置获取
     *
     * @throws IOException
     */
    public void fun_2() throws IOException {
        Properties properties = new Properties();
        InputStream inputStream = new FileInputStream(new File("C:\\Users\\李赛飞\\Desktop\\info.properties"));
        properties.load(inputStream);
        System.out.println(properties.getProperty("name"));
    }
    public void fun_3(){
        ResourceBundle bundle = ResourceBundle.getBundle("com/agile/leetcode/info");
        System.out.println(bundle.getString("age"));

    }
}
